<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {

    public $httpcode = [
        'errno' => 200,
        'error' => '连接成功'
    ];

    public function index() {
        $this->load->view('public/head');
        $this->load->view('pages/login');
    }

    public function login() {
        $redata = $this->httpcode;
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $where = [
            'username' => $username,
            'password' => $password
        ];
        $query = $this->db->select('*')->where($where)->get('qbjh_user');
        if ($query->row_array()) {
            $this->session->set_userdata($query->row_array()); //存储用户session数据
            $redata['errno'] = 666;
            $redata['error'] = '登录成功';
        } else {
            $redata['errno'] = 600;
            $redata['error'] = '登录失败,账号或密码错误';
        }
        echo json_encode($redata);
    }
    public function logout(){
        $this->session->sess_destroy();
        redirect('user/index');
    }

}
